<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>退车申请</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript" src="//cdn.staticfile.org/webuploader/0.1.5/webuploader.min.js" charset="utf-8">
    </script>
    <script src="//cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <form id="changeApplyAddForm">
        <div class="fieldset1 tabel_col tabel_col_s clearFix">
            <div class="caption">
                <span class="title">申请信息</span>
            </div>
            <div class="fieldBox col_33">
                <div class="label">融资租赁合同号</div>
                <div class="field">
                    <span name="lsCntNo" id="lsCntNo">${prjBscInfoVO.lsCntNo}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">承租人</div>
                <div class="field">
                    <span name="cstNm" id="cstNm">${prjBscInfoVO.cstNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">变更类型</div>
                <div class="field">
                    <span name="changeTypeCdNm" id="changeTypeCdNm">${changeTypeCdNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">支付表号</div>
                <div class="field">
                    <span name="paySchNo" id="paySchNo">${prjPrdPaySchMVO.paySchNo}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">项目类型</div>
                <div class="field">
                    <span name="prjTypCdNm" id="prjTypCdNm">${prjBscInfoVO.prjTypCdNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否资管业务</div>
                <div class="field">
                    <c:if test="${prjBscInfoVO.isInsBiz == '0'}">
                        <span>否</span>
                    </c:if>
                    <c:if test="${prjBscInfoVO.isInsBiz == '1'}">
                        <span>是</span>
                    </c:if>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">机构名称</div>
                <div class="field">
                    <span name="fundRasInsNm" id="fundRasInsNm">${prjBscInfoVO.fundRasInsNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否厂商业务</div>
                <div class="field">
                    <c:if test="${prjBscInfoVO.isSplMfr == '0'}">
                        <span>否</span>
                    </c:if>
                    <c:if test="${prjBscInfoVO.isSplMfr == '1'}">
                        <span>是</span>
                    </c:if>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">放款金额</div>
                <div class="field">
                    <span id="actPayAmt" name="actPayAmt" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">设备款(元)</div>
                <div class="field">
                    <span id="pAmt" name="pAmt" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">上牌状态</div>
                <div class="field">
                    <span id="spStateNm" name="spStateNm">${spStateNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">抵押状态</div>
                <div class="field">
                    <span id="dyStateNm" name="dyStateNm">${dyStateNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">实际放款时间</div>
                <div class="field">
                    <span id="actPayTm" name="actPayTm">${actPayTm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">申请日期</div>
                <div class="field">
                    <span id="crtTmStr" name="crtTmStr">${currentDate}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">资金占用天数</div>
                <div class="field">
                    <span id="fundOccDays" name="fundOccDays">${fundOccDays}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">资方放款结果</div>
                <div class="field">
                    <span id="payerStsCdNm" name="payerStsCdNm">${prjPrdPaySchMVO.payerStsCdNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">租赁年利率</div>
                <div class="field">
                    <span id="annIntRatePct" name="annIntRatePct">${prjPrdPaySchMVO.annIntRatePct}</span>%
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">供应商返利</div>
                <div class="field">
                    <span id="rebateAmt" name="rebateAmt" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">销售返利</div>
                <div class="field">
                    <span id="saleActPayAmt" name="saleActPayAmt" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">起租日</div>
                <div class="field">
                    <span id="lsDts" name="lsDts">${prjPrdPaySchMVO.lsDts}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">资金占用成本</div>
                <div class="field">
                    <span id="fundOccCost" name="fundOccCost" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">应收款金额</div>
                <div class="field">
                    <span id="recAmount" name="recAmount" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">备注</div>
                <div class="field">
                    <textarea id="remark" name="remark" rows="3" class="ui-textarea l-textarea" style="width:96%"></textarea>
                </div>
            </div>
        </div>
    </form>
    <div class="fieldset1 tabel_col tabel_col_s clearFix">
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <span>资料上传</span>
            </div>
            <div class="sqPanel_body">
                <div id="prjPrdDtlFileInfoCfgGrid" class="sq-grid"></div>
            </div>
        </div>
    </div>
    <%-- 银行账户维护--%>
    <jsp:include page="../../project/prjPrdPaySchBank/prjPrdPaySchBankAdd.jsp">
        <jsp:param name="paySchId" value="${paySchId}"/>
        <jsp:param name="isDetail_bk" value="${isDetail_bk}"/>
    </jsp:include>

    <div class="btnsBox" style="text-align: center;">
        <span id="startFlowBtn" class="sq-button sq-button-round">发起流程</span>
    </div>

    <input name="paySchId" id="paySchId" type="text" style="display: none;" value="${paySchId}">
    <input name="prjId" id="prjId" type="text" style="display: none;" value="${prjBscInfoVO.id}">
    <input name="prjPrdDtlId" id="prjPrdDtlId" type="text" style="display: none;" value="${capPayInfoVO.prjPrdDtlId}">
    <input name="changeTypeCd" id="changeTypeCd" type="text" style="display: none;" value="${changeTypeCd}">
</div>
<script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
<script type="text/javascript">
    var prjPrdDtlFileInfoCfgGrid = null;//项目资料配置明细
    $(function () {
        $('#changeApplyAddForm').ligerForm({
            validate: true
        });

        //放款金额
        var actPayAmt = '${actPayAmt}';
        if (actPayAmt) {
            $("#actPayAmt").text(FormatMoney(parseInt(actPayAmt) / 100));
        }
        //设备款
        var prdAmt = '${capPayInfoVO.prdAmt}';
        if (prdAmt) {
            $("#pAmt").text(FormatMoney(parseInt(prdAmt) / 100));
        }
        //供应商返利
        var rebateAmt = '${rebateAmt}';
        if (rebateAmt) {
            $("#rebateAmt").text(FormatMoney(parseInt(rebateAmt) / 100));
        }
        //销售返利
        var saleActPayAmt = '${saleActPayAmt}';
        if (saleActPayAmt) {
            $("#saleActPayAmt").text(FormatMoney(parseInt(saleActPayAmt) / 100));
        }
        //资金占用成本
        var fundOccCost = '${fundOccCost}';
        if (fundOccCost) {
            $("#fundOccCost").text(FormatMoney(parseInt(fundOccCost) / 100));
        }
        //应收款金额
        var recAmount = '${recAmount}';
        if (recAmount) {
            $("#recAmount").text(FormatMoney(parseInt(recAmount) / 100));
        }

        //项目资料Grid
        prjPrdDtlFileInfoCfgGrid = $("#prjPrdDtlFileInfoCfgGrid").ligerGrid({
            url: '<%=path%>/project/prjFileInfo/initPrdDtlBackOffFileList.do',
            parms: {
                prjId: '${prjBscInfoVO.id}',
                prjPrdDtlId: '${capPayInfoVO.prjPrdDtlId}',
                cfgCd: 'PRJ036'
            },
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm', align: 'left', minWidth: 100, enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var mustSymbol = '<span class="requiredSymbol">*</span>';
                        if (rowdata.isMust == 1) {
                            return value + mustSymbol;
                        } else {
                            return value;
                        }
                    }
                },
                {
                    display: '上传文件名称', name: 'fileNm', minWidth: 100, enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        if (value) {
                            var h;
                            h = '<a href="javascript:uploadFileByUrl(';
                            h += "'" + rowdata.filePath + "'";
                            h += ",'" + rowdata.fileNm + "'";
                            h += ')">' + rowdata.fileNm + '</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm',align: 'left', minWidth: 100, enabledSort: false,render:renderDate},
                {display: '状态', name: 'audStsCdNm', width: 100, enabledSort: false},
                {
                    display: '操作', name: '', minWidth: 100, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        if (rowdata.fileId && rowdata.audStsCd != 1) {
                            h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.fileId + ');"><i class="sqBtnIco_7"></i>删除</a>';
                        }
                        return h;
                    }
                },
                {
                    display: '上传', name: 'uploadNm', width: 80, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        h += '<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '" multiple name="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '"' +
                            ' class="fileupload-input" onchange="onChangefile_multi(event,\'' + rowdata.cfgCd + '\',\'' + rowdata.cfgDtlCd + '\',\'' + rowdata.orgCd + '\',2)"></span>';
                        return h;
                    }
                }
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function () {
                $('#prjPrdDtlFileInfoCfgGrid').rowspan('datNm');
                $('#prjPrdDtlFileInfoCfgGrid').rowspan('uploadNm');
            },
        });
    });

    /*发起流程*/
    $("#startFlowBtn").click(function (event) {
        $.ligerDialog.confirm("是否确认发起流程？", function (flag) {
            if (flag == false) {
                return;
            }
            var fundOccDays = $('#fundOccDays').text();
            var fundOccCost = $('#fundOccCost').text();
            var recAmount = $('#recAmount').text();
            var remark = $('#remark').val();
            if (remark && remark.length >= 400) {
                top.$.ligerDialog.SQalert({content: "备注需少于400字", SQ_type: "warning"});
                return;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {
                    changeTypeCd: '1',
                    prjId: '${prjBscInfoVO.id}',
                    cstId: '${prjBscInfoVO.cstId}',
                    cstNm: '${prjBscInfoVO.cstNm}',
                    prjTypCd: '${prjBscInfoVO.prjTypCd}',
                    lsCntNo: '${prjBscInfoVO.lsCntNo}',
                    cstMgrId: '${prjBscInfoVO.cstMgrId}',
                    cstMgrNm: '${prjBscInfoVO.cstMgrNm}',
                    cstMgrOrgCd: '${prjBscInfoVO.cstMgrOrgCd}',
                    buOrgCd: '${prjBscInfoVO.buOrgCd}',
                    prjPrdDtlId: '${capPayInfoVO.prjPrdDtlId}',
                    paySchId: '${prjPrdPaySchMVO.id}',
                    paySchNo: '${prjPrdPaySchMVO.paySchNo}',
                    fundOccDays: fundOccDays,
                    fundOccCost: fundOccCost,
                    recAmount: recAmount,
                    remark: remark,
                    paySchTypCd: '${prjPrdPaySchMVO.paySchTypCd}'
                },
                url: '<%=path%>/changeApply/flow/changeApplyFlowStart.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        var TAB = top.mainApp.parentTab;
                        var currentTabid = TAB.getSelectedTabItemID();
                        // TAB.reload(currentTabid);
                        var currFrameElement = top.$("#" + currentTabid).get(0);
                        var callback = currFrameElement.W2W.callback;
                        callback();
                        top.tab.removeTabItem(currentTabid);
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error", SQ_showButtons: true});
                    }
                }
            });
        });
    });

    //删除文件
    function delFile(event, _fileId) {
        top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
            if (!flag) {
                return;
            } else {
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fileId': _fileId},
                    url: '<%=path%>/project/prjFileInfo/removeFile.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            parent.$('li[tabid="mateTab"] a').text('项目资料(' + msg.data + ')');
                            event.stopPropagation();
                            var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                            liger.get(gridID).reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            }
        });
    }

    function onChangefile_multi(e, cfgCd, cfgDtlCd, orgCd, typ) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath = "capital/capPayInfo";

        $.ajaxFileUpload({
            url: '<%=path%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath},
            success: function (msg) {
                if (msg.success == 1) {
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {
                            'fileParams': JSON.stringify(msg.data),
                            'prjPrdDtlId': $("#prjPrdDtlId").val(),
                            'cfgCd': cfgCd,
                            'cfgDtlCd': cfgDtlCd,
                            'orgCd': orgCd
                        },
                        url: '<%=path%>/project/prjFileInfo/uploadPrjPrdDtlFile.do',
                        success: function (msg) {
                            if (msg.success == 1) {
                                prjPrdDtlFileInfoCfgGrid.reload();
                            } else {
                                $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                            }
                            $.ligerDialog.hide();
                        }
                    });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    };

    function uploadFileByUrl(_url, _name) {
        if (SQ.regs.img.test(_name)) {
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        } else if (SQ.regs.img.test(_url)) {
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        } else {
            window.open(_url);
        }
    }

    function downFile(_url) {
        window.open(_url);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
</script>
</body>
</html>
